<template>
	<div class="product-add">
		<!--form表单-->
		<el-form size="small" ref="form" :model="form" label-width="260px">
			<!--添加门店-->
			<div class="common-form">修改电子面单配置</div>
			<el-form-item label="电子面单配置名称 " prop="setting_name" :rules="[{required: true,message: ' '}]">
				<el-input v-model.trim="form.setting_name" class="max-w460"></el-input>
			</el-form-item>

			<el-form-item label="快递公司">
				<el-select size="small" v-model="form.express_id" placeholder="请选择">
					<el-option v-for="(item, index) in expressList" :key="index" :label="item.express_name"
						:value="item.express_id">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="电子面单月结账号(partner_id)" prop="partner_id" :rules="[{required: true,message: ' '}]">
				<el-input v-model.trim="form.partner_id" class="max-w460"></el-input>
				<div class="tips">电子面单客户编码或月结账号，使用电子面单下单时必填，需贵司向当地快递公司网点申请，其余字段请对照快递100参数字典根据快递公司类型填写
					<el-link :underline="false" href="https://api.kuaidi100.com/document/5f0ff6e82977d50a94e10237.html"
						target="_blank" type="primary">快递100参数字典
					</el-link>
				</div>
				<div class="tips"></div>
			</el-form-item>
			<el-form-item label="电子面单密码(partner_key)">
				<el-input v-model.trim="form.partner_key" class="max-w460"></el-input>
			</el-form-item>
			<el-form-item label="电子面单密钥(partner_secret)">
				<el-input v-model.trim="form.partner_secret" class="max-w460"></el-input>
			</el-form-item>
			<el-form-item label="电子面单客户账户名称(partner_name)">
				<el-input v-model.trim="form.partner_name" class="max-w460"></el-input>
			</el-form-item>
			<el-form-item label="收件网点名称(net)">
				<el-input v-model.trim="form.net" class="max-w460"></el-input>
			</el-form-item>
			<el-form-item label="电子面单承载编号(code)">
				<el-input v-model.trim="form.code" class="max-w460"></el-input>
			</el-form-item>
			<el-form-item label="电子面单承载快递员名(check_man)">
				<el-input v-model.trim="form.check_man" class="max-w460"></el-input>
			</el-form-item>

			<el-form-item label="排序">
				<el-input v-model.trim="form.sort" type="number" class="max-w460"></el-input>
				<div class="tips">数字越小越靠前</div>
			</el-form-item>

			<el-form-item label="排序">
				<el-input v-model.trim="form.sort" type="number" class="max-w460"></el-input>
				<div class="tips">数字越小越靠前</div>
			</el-form-item>
			<!--提交-->
			<div class="common-button-wrapper">
				<el-button size="small" type="info" @click="cancelFunc">取消</el-button>
				<el-button type="primary" @click="onSubmit" :loading="loading">提交</el-button>
			</div>
		</el-form>
	</div>
</template>

<script>
import {
	getLabelEdit,
	labelEdit
} from '@/api/setting.js';

export default {
	data() {
		return {
			/*切换菜单*/
			// activeIndex: '1',
			/*form表单数据*/
			form: {
				setting_id: 0,
				wxCode: '',
				sort: ''
			},
			/*快递公司列表*/
			expressList: [],
			loading: false
		};
	},
	created() {
		this.getData();
	},

	methods: {
		/*获取数据*/
		getData() {
			let self = this;
			// 取到路由带过来的参数
			const params = this.$route.query.setting_id;
			getLabelEdit({
				setting_id: params
			},
			true
			)
				.then(res => {
					let detail = res.data.model;
					// 将数据放在当前组件的数据内
					self.form = detail;
					self.expressList = res.data.expressList;
				})
				.catch(error => {});
		},

		/*提交表单*/
		onSubmit() {
			let self = this;
			self.loading = true;
			let params = this.form;
			labelEdit(params, true)
				.then(data => {
					self.loading = false;
					ElMessage({
						message: '恭喜你，修改成功',
						type: 'success'
					});
					self.$router.push('/setting/label/index');
				})
				.catch(error => {
					self.loading = false;
				});
		},
		/*取消*/
		cancelFunc() {
			this.$router.push({
				path: '/setting/label/index'
			});
		}
	}
};
</script>

<style>
	.tips {
		color: #ccc;
	}
</style>